/* ----------------------------------------------------------------------------------------------------------------
 *  Fragment
 * ----------------------------------------------------------------------------------------------------------------
 */
package pure.engine.entity 
{
	import flash.display.Bitmap;
	import pure.engine.core.ns_despair;
	import pure.engine.renderer.Renderer;
	import pure.engine.core.ns_despair;

	use namespace ns_despair
	
	/**
	 * 碎片(残像组件)
	 * [Author] - PURE
	 * 
	 */
final public class Fragment extends Bitmap 
{
	public function Fragment()
	{
		super(null, 'never');
	}
	

	// 生成碎片
	ns_despair static function makeFragment():Fragment
	{
		if (m_numFragment > 0)
		{
			--m_numFragment
			return fragmentList.pop();
		}
		return new Fragment();
	}

	
	// 是否可交互
	final ns_despair function get interactive():Boolean
	{
		return entity.m_interactive && renderer.m_interactive;
	}
	
	
	// 回收
	final ns_despair function recycle():void
	{
		entity = null;
		renderer = null;
		this.bitmapData = null;
		fragmentList[m_numFragment++] = this;
	}

	
	
	
	
	//======================
	// Member
	//======================
	
	
	ns_despair var entity:Entity;
	
	ns_despair var renderer:Renderer;
	
	ns_despair static var fragmentList:Vector.<Fragment>  =  new Vector.<Fragment>();
	
	ns_despair static var m_numFragment:int;

}
}